package com.ctshk.app.cms.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.cms.dto.NoticeDTO;
import com.ctshk.rpc.cms.req.*;
import com.ctshk.rpc.cms.service.INoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 公告管理 前端控制器
 * </p>
 *
 * @author LiZhiming
 * @since 2021-04-23
 */
@Api(value = "公告管理-app", tags = "公告管理-app")
@RestController
@RequestMapping("/notice-app")
public class NoticeController extends BaseController {
    @DubboReference
    private INoticeService noticeService;

    @ApiOperation(value = "新增公告-app", notes = "新增公告-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.ADD)
    @PostMapping("/add")
    public Result add(@RequestBody @Valid NoticeAddReq req) {
        return noticeService.insert(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "查询公告-app", notes = "查询公告-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @GetMapping("/queryById/{noticeId}")
    public Result<NoticeDTO> queryById(@PathVariable("noticeId") String noticeId) {
        return noticeService.queryById(noticeId);
    }

    @ApiOperation(value = "公告分页查询-app", notes = "公告分页查询-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryList")
    public PageResponse<NoticeDTO> queryList(@RequestBody @Valid NoticeQueryReq req) {
        return noticeService.queryList(req);
    }

    @ApiOperation(value = "查询公告s-app", notes = "查询公告s-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.QUERY)
    @PostMapping("/queryListByCode")
    public List<NoticeDTO> queryListByCode(@RequestBody @Valid BannerPositionByTypeReq req) {
        return noticeService.queryListByCode(req);
    }

    @ApiOperation(value = "修改公告-app", notes = "修改公告-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/update")
    public Result update(@RequestBody @Valid NoticeUpdateReq req) {
        return noticeService.update(req, getCurrentUser(getRequest()));
    }

    @ApiOperation(value = "修改有效状态-app", notes = "修改有效状态-app")
    @OperationLogAnnotation(operModul = OperationLogModel.CMS, operType = OperationLogType.UPDATE)
    @PostMapping("/updateStatusById")
    public Result updateStatusById(@RequestBody @Valid UpdateStatusReq req) {
        return noticeService.updateStatusById(req);
    }
}
